import { Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { _HttpClient, ModalHelper } from '@delon/theme';
import { STColumn, STComponent } from '@delon/abc';
import { SFSchema } from '@delon/form';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { FormBuilder } from '@angular/forms';
import { ApiService } from '@core/services/api';
import { HouseDetailComponent } from '../house-detail/house-detail.component';
import { AreaService } from '../../sys-setting/area-manage/area.service';

@Component({
  selector: 'app-house-manage-house-list',
  templateUrl: './house-list.component.html',
  styleUrls: ['./index.less']
})
export class HouseListComponent implements OnInit, OnDestroy {
  @ViewChild('st', { static: false }) st: STComponent;
  location$;
  items = []
  param = {
    houseCode: '',
    houseAddress: '',
    pageSize: 20,
    pageNum: 1,
    total: 0,
  }
  selectedData: any;


  constructor(
    private http: _HttpClient,
    public msg: NzMessageService,
    private fb: FormBuilder,
    private api: ApiService,
    private modal: NzModalService,
    private area: AreaService
    ) { }

  ngOnInit() {
    this.getHouseList(this.param);
    this.location$ = this.area.getLocation().subscribe(res => {
      this.searchData(1);
    })
  }
  ngOnDestroy(): void {
    this.location$.unsubscribe();
  }

  // 模拟数据
  addItemsArr() {
    this.items.forEach((item) => {
      if (this.items.length < 20) {
        this.items.push(item);
        this.addItemsArr();
      }
    })
  }
  // 点击房屋列表弹框
  openModal(_param: any, header: TemplateRef<Element>) {
    this.selectedData = _param;
   this.modal.create({
     nzTitle: header,
     nzContent: HouseDetailComponent,
     nzWidth: '70%',
     nzFooter: null,
     nzComponentParams: {
       _param
     }
   })
  }
  // 搜索
  searchData(pi) {
    this.param.pageNum = pi;
    this.getHouseList(this.param);
  }

  selectChange(): void {
    
  }

  /**
   * 后去楼栋列表
   * @param param 检索参数
   */
  getHouseList(param): void {
    const body = param
    this.http.request<any>(this.api.house.page.method, this.api.house.page.url, {body}).subscribe(res => {
      if (res.status === '200') {
        this.items = res.data.list;
        this.param.total = res.data.total;
      }
    })
  }
  getStatistic(id: string): void {

  }
}
